﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DbFramework.Data.Extension
{
    public static class ExtDataSet
    {
        public static DataSet Paging(this DataSet value, int pageIndex, int pageSize)
        {
            if (value.Tables == null)
            {
                return null;
            }
            if (value.Tables.Count == 0)
            {
                return null;
            }
            DataRow[] drs = value.Tables[0].AsEnumerable().Skip(pageIndex * pageSize).Take(pageSize).ToArray();
            DataSet newDataset = new DataSet();
            newDataset.Tables.Add(value.Tables[0].Clone());
            for(int i=0;i<drs.Count();i++)
            {
                newDataset.Tables[0].ImportRow(drs[i]);
            }
            return newDataset;
        }
    }
}
